home *** CD-ROM | disk | FTP | other *** search
/ Popular Request / By Popular Request (Arsenal Computer)(SysOptics Distribution System).ISO / amiga4 / timer.lha / Timer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-30  |  1.6 KB  |  70 lines

  1. #include <exec/types.h>
  2. #include <exec/tasks.h>
  3. #include <dos/dos.h>
  4. #include <dos/dostags.h>
  5. #include <devices/timer.h>
  6.  
  7. #include <clib/exec_protos.h>
  8. #include <clib/dos_protos.h>
  9. #include <clib/timer_protos.h>
  10.  
  11. #define _USEOLDEXEC_
  12. #include <proto/exec.h>
  13. #include <proto/dos.h>
  14. #include <proto/timer.h>
  15.  
  16. #include "Timer_rev.h"
  17.  
  18. __asm LONG Timer(register __a0 STRPTR argptr, register __d0 LONG arglen)
  19. {
  20.     struct DosLibrary *DOSBase;
  21.     struct Library *TimerBase;
  22.  
  23.     struct MsgPort *tp;
  24.     struct timerequest *tr;
  25.     struct timeval start, end;
  26.     struct Task *task;
  27.     LONG rc = RETURN_FAIL;
  28.  
  29.     if(DOSBase = (struct DosLibrary *)OpenLibrary("dos.library" VERSTAG " by Flavio Stanchina", 37))
  30.     {
  31.         /* Null-terminate command line */
  32.         argptr[--arglen] = '\0';
  33.  
  34.         if(tp = CreateMsgPort())
  35.         {
  36.             if(tr = (struct timerequest *)CreateIORequest(tp, sizeof(struct timerequest)))
  37.             {
  38.                 /* Use UNIT_MICROHZ if you want accuracy on short intervals */
  39.                 /* Use UNIT_VBLANK if you want stability over time and low overhead */
  40.                 if(OpenDevice("timer.device", UNIT_MICROHZ, tr, 0) == 0)
  41.                 {
  42.                     TimerBase = (struct Library *)tr->tr_node.io_Device;
  43.  
  44.                     task = FindTask(NULL);
  45.  
  46.                     /* Time command */
  47.                     GetSysTime(&start);
  48.                     rc = SystemTags(argptr,
  49.                         NP_StackSize, task->tc_SPUpper - task->tc_SPLower,
  50.                         TAG_END);
  51.                     GetSysTime(&end);
  52.  
  53.                     /* Print result */
  54.                     SubTime(&end, &start);
  55.                     VPrintf("*** Time: %ld.%06ld secs\n", (LONG *)&end);
  56.  
  57.                     CloseDevice((struct IORequest *)tr);
  58.                 }
  59.                 else PutStr("Can't open timer device\n");
  60.  
  61.                 DeleteIORequest((struct IORequest *)tr);
  62.             }
  63.             DeleteMsgPort(tp);
  64.         }
  65.         CloseLibrary((struct Library *)DOSBase);
  66.     }
  67.  
  68.     return rc;
  69. }
  70.